package com.lishe.lishe.lishe.module.myorder.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.myorder.bean.StepsBean;

import java.util.LinkedList;

/**
 * Created by shino on 2017/10/22.
 */

public class LogisticsAdapter extends RecyclerView.Adapter<LogisticsAdapter.LogisticsHolder> {
    private Context mContext;
    private LinkedList<StepsBean> mList;

    public LogisticsAdapter(Context context, LinkedList<StepsBean> list) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public LogisticsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_activity_logistics, null);
        return new LogisticsHolder(view);
    }

    @Override
    public void onBindViewHolder(LogisticsHolder holder, int position) {
       holder.step.setText(mList.get(position).getNote());
       holder.time.setText(mList.get(position).getTime());
       if (position == 0) {
           holder.step.setTextColor(mContext.getResources().getColor(R.color.color_ff4138));
           holder.topline.setVisibility(View.INVISIBLE);
           holder.point.setBackgroundColor(mContext.getResources().getColor(R.color.color_ff4138));
           holder.bottomline.setVisibility(View.VISIBLE);
       } else if (position == mList.size() - 1) {
           holder.step.setTextColor(mContext.getResources().getColor(R.color.gray_3));
           holder.topline.setVisibility(View.VISIBLE);
           holder.point.setBackgroundColor(mContext.getResources().getColor(R.color.color_eeeeee));
           holder.bottomline.setVisibility(View.INVISIBLE);
       } else {
           holder.step.setTextColor(mContext.getResources().getColor(R.color.gray_3));
           holder.topline.setVisibility(View.VISIBLE);
           holder.point.setBackgroundColor(mContext.getResources().getColor(R.color.color_eeeeee));
           holder.bottomline.setVisibility(View.VISIBLE);
       }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class LogisticsHolder extends RecyclerView.ViewHolder {
        private TextView step;
        private TextView time;
        private View topline;
        private View bottomline;
        private View point;

        public LogisticsHolder(View v) {
            super(v);
            step = v.findViewById(R.id.step);
            time = v.findViewById(R.id.time);
            topline = v.findViewById(R.id.topline);
            bottomline = v.findViewById(R.id.bottomline);
            point = v.findViewById(R.id.point);
        }
    }
}
